$(function(){
	$(':input').labelauty()	
	//Txt文本导入
	$("#importTxt").click(function () {
        $("#numberFile").click();
    });
	
	$("#fileForm").ajaxForm({
        success: function (data) {
            $("#mobilenumbers").val(data);
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert("操作失败:服务器错误");
        }
    });
	//过滤错号
	$("#checkMobile").click(function () {
		$("#pkg").empty();
		var numberMeg = $("#mobilenumbers").val();
		var dataType = $("input[name='dataType']:checked").val();
     		$.ajax({
     			type : "post",
     			url:basePath+"dataChargeBatchCheckPhone",
     			data:{numberMeg:numberMeg,
     				dataType:dataType
     				},
     			success:function(data){
     				if (data != "" && data != null) {
     					$("#terminalName").val(data.agentName);
     					$("#mobilenumbers").val(data.phone);
     					var count = data.count;
     					var valid = data.valid;
     					var inValid = data.inValid;
     					countNum(count,valid,inValid);
     					var meg=$("#meg");
     					var dt=data.phoneMeg;
     					for(var key in dt)
         				{
     						var pkgData=dt[key];
     						var li='<li>'+pkgData+'</li>'
     						var ul='<ul class="dowebok">'+li+'</ul>';
     	           			var div2='<div class="col-sm-8">'+ul+'</div>';
     	     				var label='<label class="col-sm-2 control-label">'+key+'</label>';
     	         			var div='<div class="form-group ">'+label+div2+'</div>';	
     	         			meg.append(div);
         				}	
     				}else{
     					swal({
         			        title: "系统异常",
         			        type: "success",
         			        confirmButtonText: "ok"
         				});
     				}
     			},
     			error:function(data){
     				swal({
     			        title: "系统异常",
     			        type: "success",
     			        confirmButtonText: "ok"
     				});
     			},
     			dataType : "json",
     		});
	});
	
	setMyActive(4,2,2); //设置激活页
});

function countNum(count,valid,inValid) {
	
    $("#countNumMsg").html("共计号码：<font color=\"red\">" + count + " </font>个" +
    		",有效号码：<font color=\"red\">" + valid + " </font>个" +
    		",无效号码：<font color=\"red\">" + inValid + " </font>个<i class=\"fa fa-info-circle\"></i>");
}

//号码变动时的操作锁定提交按钮
function lockSubmitButton(){
$("#submitButtonId").attr("disabled", true);
}

function checkType(){
	$("#meg").empty();
}

function submitOrder() {
	var terminalName = $("#terminalName").val(); 
	var phoneNo = $("#mobilenumbers").val();
	var orderType = "1";
	var scope = "nation";
	var type = "2";
	$.ajax({
		type : "get",
		url : basePath + 'order/webSubmit',
		data : {
			'terminalName': terminalName,
			'phoneNo': phoneNo,
			'orderType': orderType,
			scope: scope,
			type:type
		},
		success : function(dt) {
			swal({
			        title:"返回信息",
			        text:"提交成功"+dt.success+"个，提交失败"+dt.error+"个,失败信息:"+dt.errorMessage,
			        type: "success",
			        confirmButtonText: "ok"
				});
		},
		error:function(data){
				swal({
 			        title: "系统异常",
 			        type: "success",
 			        confirmButtonText: "ok"
 				});
 			},
		dataType : 'json'
	});
}
